package com.rover022.flixelgame.ui.heroresolve
{
	import com.greensock.events.LoaderEvent;
	import com.rover022.flixelgame.manager.AssetManager;
	import com.rover022.flixelgame.manager.EventHelper;
	import com.rover022.flixelgame.manager.PlayerManager;
	import com.rover022.flixelgame.manager.WorldManager;
	import com.rover022.flixelgame.ui.BaseUI;
	import com.rover022.flixelgame.vo.UserVo;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;

	/**
	 * 玩家主UI界面
	 * 包括了界面上按钮  金钱显示 钻石显示 头像显示
	 *
	 */
	public class PlayInfoAndMenuUI extends BaseUI
	{
		public var swfId:String = "ui/MainUI.swf";
		public var classId:String = "assets.baseui.mianbar";

		public function PlayInfoAndMenuUI()
		{
			name = "PlayerInfoUI";
			AssetManager.getInstance().loadAssetArray([swfId], initUI);
		}

		override public function initUI(e:LoaderEvent = null):void
		{
			assetUI = AssetManager.getInstance().requestAssetInstance(swfId, classId);
			var _userVo:UserVo = PlayerManager.getInstance().getUserVo();
			_userVo.register(this);
			setImage(_userVo.headImage);
			update();
			EventHelper.addEventListener(heroreSolveButton, MouseEvent.CLICK, menusClickHandle); //玩家面板点击
			EventHelper.addEventListener(battleButton, MouseEvent.CLICK, menusClickHandle);      //玩家副本点击
			EventHelper.addEventListener(equipupButton, MouseEvent.CLICK, menusClickHandle);     //玩家装备升级点击
			EventHelper.addEventListener(itemButton, MouseEvent.CLICK, menusClickHandle);        //玩家包裹点击
			addChild(assetUI);
		}

		protected function menusClickHandle(event:Event):void
		{
			WorldManager.getInstance().showPop(event.currentTarget.name);
		}

		override public function update():void
		{
			var _userVo:UserVo = PlayerManager.getInstance().getUserVo();
			goldMc.numTxt.text = _userVo.gold.toString();
			gemMc.numTxt.text = _userVo.gem.toString();
			powerMc.numTxt.text = _userVo.power.toString();
			headMc.lvTxt.text = _userVo.lv.toString();
			headMc.nameTxt.text = _userVo.playName;
			setExp(_userVo.exp);
		}

		private function setExp(exp:uint):void
		{
			// TODO Auto Generated method stub
		}

		private function setImage(headImage:String):void
		{
			// TODO Auto Generated method stub
		}

		private function get gemMc():MovieClip
		{
			return assetUI.getChildByName("gemMc") as MovieClip;
		}

		private function get goldMc():MovieClip
		{
			return assetUI.getChildByName("goldMc") as MovieClip;
		}

		private function get headMc():MovieClip
		{
			return assetUI.getChildByName("headMc") as MovieClip;
		}

		private function get powerMc():MovieClip
		{
			return assetUI.getChildByName("powerMc") as MovieClip;
		}

		private function get heroreSolveButton():DisplayObject
		{
			return assetUI.getChildByName("heroreSolve");
		}

		private function get battleButton():DisplayObject
		{
			return assetUI.getChildByName("battleButton");
		}

		private function get equipupButton():DisplayObject
		{
			return assetUI.getChildByName("equipupButton");
		}

		private function get itemButton():DisplayObject
		{
			return assetUI.getChildByName("itemButton");
		}
	}
}
